package operation;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-05-19
 * Time:21:11
 */
public class DelOperation implements IOperation{
    @Override
    public void work(BookList books) {
        System.out.println("删除书籍");
        System.out.println("请输入要删除的书籍书名->");
        Scanner scanner =new Scanner(System.in);
        String name=scanner.nextLine();
        for (int i = 0; i < books.getSize(); i++) {
            if(books.getBook(i).getName().equals(name)){
                for (int j = i; j < books.getSize()-1; j++) {
                    books.setBook(j,books.getBook(j+1));
                }
                books.setSize(books.getSize()-1);
                System.out.println("删除成功!");
            }
        }

    }
}
